package com.sgb.goods.view.activity;

import android.view.inputmethod.EditorInfo;

import com.alibaba.android.arouter.facade.annotation.Route;
import com.blankj.utilcode.util.KeyboardUtils;
import com.sgb.goods.BR;
import com.sgb.goods.R;
import com.sgb.goods.databinding.GoodsActivityManageListBinding;
import com.sgb.goods.utils.Constants;
import com.sgb.goods.utils.base.BaseActivity;
import com.sgb.goods.viewmodel.GoodsManageListViewModel;

/**
 * 个人中心 - 商品管理
 * @author cyj
 */
@Route(path = Constants.ARouter.AR_GOODS_MANAGE_LIST)
public class GoodsManageListActivity extends BaseActivity<GoodsActivityManageListBinding, GoodsManageListViewModel> {

    @Override
    protected int getLayoutResId() {
        return R.layout.goods_activity_manage_list;
    }

    @Override
    protected void initViewModel() {
        mViewModel = createViewModel(GoodsManageListViewModel.class, BR.viewModel);
    }

    @Override
    protected void initListener() {
        mDataBinding.backView.setOnClickListener(v -> finish());

        // 批量按钮监听
        mDataBinding.tvBatch.setOnClickListener(v -> {
            mViewModel.isBatch.setValue(null == mViewModel.isBatch.getValue() || !mViewModel.isBatch.getValue());
        });

        mDataBinding.editSearch.setOnEditorActionListener((v, actionId, event) -> {
            if(EditorInfo.IME_ACTION_SEARCH == actionId) {
                KeyboardUtils.hideSoftInput(mDataBinding.editSearch);
                mViewModel.searchContent.setValue(v.getText().toString().trim());
                return true;
            }
            return false;
        });

    }

}
